//
//  HLBlackListViewController.m
//  YueYue
//
//  Created by hulu001 on 2023/5/19.
//

#import "HLBlackListViewController.h"
#import "HLBlackCell.h"
#import "HLFriendsListRequest.h"

@interface HLBlackListViewController ()

@end

@implementation HLBlackListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorWhite;
    self.request = [[HLFriendsListRequest alloc] initWithType:HLFriendTypeBlack];
    self.request.delegate = self;
    [self requestInit];
}

- (void)requestInit
{
    [self showEmptyView];
    [self.emptyView.loadingView startAnimating];
    [self.emptyView setTextLabelText:@"加载中..."];
    [self.request start];
}

- (void)setupNavigationItems
{
    [super setupNavigationItems];
    self.title = @"黑名单";
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDarkContent;
}

- (UIImage *)qmui_navigationBarBackgroundImage
{
    return [UIImage qmui_imageWithColor:UIColorWhite];
}

- (nullable UIColor *)qmui_navigationBarTintColor
{
    return UIColorBlack;
}

- (void)initTableView
{
    [super initTableView];
    [self setupMJRefresh];
    [self.tableView registerClass:[HLBlackCell class] forCellReuseIdentifier:[HLBlackCell identifyCell]];
    self.tableView.backgroundColor = HLBackgroundColor;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datasources.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HLBlackCell *cell = [tableView dequeueReusableCellWithIdentifier:[HLBlackCell identifyCell]];
    if (self.datasources.count <= indexPath.row){
        return cell;
    }
    cell.model = self.datasources[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    GPBlackModel *blackModel = self.datasources[indexPath.row];
//    GPUserDetailVC *userDetailVC = [[GPUserDetailVC alloc] initWithUserId:blackModel.maleUserId client:blackModel.client];
//    [self.navigationController pushViewController:userDetailVC animated:YES];
}


- (void)headerRefresh
{
    HLFriendsListRequest *blackRequest = (HLFriendsListRequest *)self.request;
    blackRequest.page = 1;
    [self.request start];
}

- (void)footerRefresh
{
    HLFriendsListRequest *blackRequest = (HLFriendsListRequest *)self.request;
    blackRequest.page += 1;
    [self.request start];
}


- (void)requestFinished:(__kindof YTKBaseRequest *)request
{
    [super requestFinished:request];
    
    HLFriendsListRequest *blackRequest = (HLFriendsListRequest *)request;
    if (blackRequest.page == 1){
        [self.datasources removeAllObjects];
    }
    [self.datasources addObjectsFromArray:blackRequest.friendsList];
    if (blackRequest.friendsList.count == 0){
        [self.emptyView setLoadingViewHidden:YES];
        [self.emptyView setImage:UIImageMake(@"empty_icon_2")];
        [self.emptyView setTextLabelText:@"哇哦，你和朋友聊的都很好 这里一个人也没有～"];
    } else {
        [self hideEmptyView];
    }
    
    [self.tableView reloadData];
}

- (void)requestFailed:(__kindof YTKBaseRequest *)request
{
    [super requestFailed:request];
}

#pragma mark - JXCategoryListContentViewDelegate

/**
 实现 <JXCategoryListContentViewDelegate> 协议方法，返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}


@end
